package com.metaera.app.controller.presenter;

import com.metaera.app.controller.core.RequestPresenter;
import com.metaera.app.controller.view.core.INetworkRequestView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.data.rx.ResponseObserver;
import com.metaera.app.data.rx.SchedulersTransformer;

public class FollowAuthorPresenter extends RequestPresenter<INetworkRequestView<Object>> {

    public void follow(int id, boolean isFollow) {
        DataRepository.getInstance()
                .followAuthor(id, isFollow ? ApiParam.FOLLOW_AUTHOR : 0)
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

    public void notice(int id, boolean isNotice){
        DataRepository.getInstance()
                .updateAuthorNotice(id, isNotice ? 1 : 0)
                .compose(SchedulersTransformer.transformer())
                .subscribe(new ResponseObserver<>(
                                this,
                                mView,
                                response -> mView.successful(response.getData())
                        )
                );
    }

}
